package logic

import (
	"context"
	"errors"
	"gozero-microservices/gateway-api/internal/svc"
	"gozero-microservices/user-service/rpc/types/userDeliveryAddress"

	"github.com/zeromicro/go-zero/core/logx"
)

/*
 +----------------------------------------------------------------------
 + Title        : UserDeliveryAddrLogic
 + Author       : huwl
 + Version      : 1.0.0
 + Initial-Time : 2025-08-08
 + Last-time    : 这个文件最后修改的时间 + 修改人的名称
 + Desc         : 用户收货地址逻辑
 +----------------------------------------------------------------------
*/

type UserDeliveryAddrLogic struct {
	BaseLogic
}

/**
 * 创建横幅逻辑实例
 *
 * @param context.Context ctx ----------------------必传
 * @param *svc.ServiceContext svcCtx ---------------必传
 * @return *UserDeliveryAddrLogic
 * @author huwl
 * @date 2025/10/22 12:54:03
 */
func NewUserDeliveryAddrLogicInstance(ctx context.Context, svcCtx *svc.ServiceContext) *UserDeliveryAddrLogic {
	return &UserDeliveryAddrLogic{
		BaseLogic{
			Ctx:    ctx,
			SvcCtx: svcCtx,
			Logger: logx.WithContext(ctx),
		},
	}
}

/**
 * 详情
 *
 * @param uint64 Id ---------------------------必传,Id
 * @return *userDeliveryAddress.DetailResponse, error
 * @author huwl
 * @date 2025/10/22 10:15:55
 */
func (logic *UserDeliveryAddrLogic) Detail(id uint64) (*userDeliveryAddress.DetailResponse, error) {
	if id <= 0 {
		return nil, errors.New("Id错误")
	}

	// 远程调用用户服务之用户收货地址服务
	return logic.SvcCtx.UserDeliveryAddrSrv.UserDeliveryAddrDetail(logic.Ctx, &userDeliveryAddress.DetailRequest{Id: id})
}
